package net.linku.utils;

import java.security.SecureRandom;

/**
 * @ClassName NicknameGeneratorUtil
 * @Description: 昵称工具类，随机生成
 * @Author SilenceTian
 * @Date 2024/1/4
 * @Version V1.0.2
 **/
public class UserNameGeneratorUtil {

    private static final String ALLOWED_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
    private static final int NICKNAME_LENGTH = 9;

    private static final SecureRandom secureRandom = new SecureRandom();

    public static String generateUserName() {
        StringBuilder randomNickname = new StringBuilder(NICKNAME_LENGTH);
        randomNickname.append("L");  // Ensure the nickname starts with 'L'

        for (int i = 1; i < NICKNAME_LENGTH; i++) {
            int randomIndex = secureRandom.nextInt(ALLOWED_CHARACTERS.length());
            char randomChar = ALLOWED_CHARACTERS.charAt(randomIndex);
            randomNickname.append(randomChar);
        }

        return randomNickname.toString();
    }

    public static void main(String[] args) {
        // Example usage
        String randomNickname = generateUserName();
        System.out.println("Random UserName: " + randomNickname);
    }
}
